package com.soilflow.info.service.impl;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.soilflow.common.domain.SysArticle;
import com.soilflow.common.domain.SysCategory;
import com.soilflow.common.domain.vo.categorySearchVo;
import com.soilflow.common.excle.DuocaiCategoryExcel;
import com.soilflow.common.excle.DuocaiCollectExcel;
import com.soilflow.common.utils.DateUtils;
import com.soilflow.info.mapper.SysCategoryMapper;
import com.soilflow.info.service.ISysArticleService;
import com.soilflow.info.service.ISysCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;

/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author party
 * @date 2023-10-12
 */
@Service
public class SysCategoryServiceImpl extends ServiceImpl<SysCategoryMapper, SysCategory> implements ISysCategoryService {
    @Autowired
    private SysCategoryMapper sysCategoryMapper;
    @Autowired
    private ISysArticleService sysArticleService;

    /**
     * 查询【请填写功能名称】
     * 
     * @param id 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public SysCategory selectSysCategoryById(Long id)
    {
        return sysCategoryMapper.selectSysCategoryById(id);
    }

    /**
     * 查询【请填写功能名称】列表
     * 
     * @param sysCategory 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<SysCategory> selectSysCategoryList(SysCategory sysCategory)
    {
        return sysCategoryMapper.selectSysCategoryList(sysCategory);
    }

    /**
     * 新增【请填写功能名称】
     * 
     * @param sysCategory 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertSysCategory(SysCategory sysCategory)
    {
        sysCategory.setCreateTime(DateUtils.getNowDate());
        return sysCategoryMapper.insertSysCategory(sysCategory);
    }

    /**
     * 修改【请填写功能名称】
     * 
     * @param sysCategory 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateSysCategory(SysCategory sysCategory)
    {
        sysCategory.setUpdateTime(DateUtils.getNowDate());
        return sysCategoryMapper.updateSysCategory(sysCategory);
    }

    /**
     * 批量删除【请填写功能名称】
     * 
     * @param ids 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteSysCategoryByIds(Long[] ids)
    {
        return sysCategoryMapper.deleteSysCategoryByIds(ids);
    }

    /**
     * 删除【请填写功能名称】信息
     * 
     * @param id 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteSysCategoryById(Long id)
    {
        return sysCategoryMapper.deleteSysCategoryById(id);
    }

    @Override
    public List<SysCategory> categoryList() {
        LambdaQueryWrapper<SysCategory> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(SysCategory::getDeleted,0);
        List<SysCategory> list = list(wrapper);
        return list;
    }

    @Override
    public Long selectCategoryById(String categoryName) {
        LambdaQueryWrapper<SysCategory> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(SysCategory::getCategoryName,categoryName);
        SysCategory category = this.getOne(wrapper);
        return category.getId();
    }

    @Override
    public void export(HttpServletResponse response) throws IOException {
         List<DuocaiCategoryExcel> excelList = this.baseMapper.export();
        EasyExcel.write(response.getOutputStream(), DuocaiCategoryExcel.class).sheet().doWrite(excelList);
    }


}
